/**
 @Name：CLTPHP 后台登录
 @Author：chichu
 @Site：http://www.cltphp.com/admin/
 @License: LPPL
 */
layui.define('form', function (exports) {
    var $ = layui.$
        , layer = layui.layer
        , laytpl = layui.laytpl
        , setter = layui.setter
        , view = layui.view
        , admin = layui.admin
        , form = layui.form;

    var $body = $('body');
    //更换图形验证码
    $body.on('click', '#LAY-user-get-vercode', function () {
        var verifyUrl = $(this).data('url');
        this.src = verifyUrl + '?t=' + new Date().getTime()
    });
    form.on('submit(login-submit)', function (obj) {
        //请求登入接口
        admin.req({
            url: "/shengteng/login/login" //实际使用请改成服务端真实接口
            , data: obj.field
            , type:'post'
            , success: function (res) {
                //登入成功的提示与跳转
                if(res.code>0){
                    $('#LAY-user-login-vercode').val('');
                    var verifyUrl = $('#LAY-user-get-vercode').data('url');
                    $('#LAY-user-get-vercode').attr('src',verifyUrl+'?t=' + new Date().getTime());
                }else{
                    layer.msg(res.msg, {
                        offset: '15px', icon: 1, time: 1000
                    }, function () {
                        location.href = adminUrl; //后台主页
                    });
                }
            }
        });
    });
    //对外暴露的接口
    exports('login', {});
});
